package designmode.strategy;

/**
 * Created by Administrator on 2017/10/28 028.
 */
public abstract class Duck
{
    protected Tweetbehavior tweetbehavior;
    protected FlyBehavior flyBehavior;

    public Duck()
    {
        tweetbehavior = getTweetBehavior();
        flyBehavior = getFlyBehavior();
    }

    protected abstract FlyBehavior getFlyBehavior();

    protected abstract Tweetbehavior getTweetBehavior();

    public void setTweetbehavior(Tweetbehavior t)
    {
        tweetbehavior = t;
    }

    public void setFlyBehavior(FlyBehavior f)
    {
        flyBehavior = f;
    }

    protected void performTweet()
    {
        if(tweetbehavior != null)
        {
            tweetbehavior.tweet();
        }
    }

    protected void performFly()
    {
        if(flyBehavior != null)
        {
            flyBehavior.fly();
        }
    }
}
